import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [
    	{
    		title: '下山 (改编版)',
    		author: '小熊纯一郎',
    		src: require('../assets/music/xs.mp3'),
        img: require('../assets/img/About/kegou.jpg'),
        hash: 'we',
        album_id: '666',
    		lyric: [
    			{ time: '[00:00.00]', name: '小熊纯一郎 - 下山 (改编版)' },
    			{ time: '[00:13.33]', name: '要想寒假轻松过冬' },
    			{ time: '[00:15.33]', name: '先要忍受磨人期末考的痛' },
    			{ time: '[00:18.41]', name: '平时上课不认真玩世不恭' },
    			{ time: '[00:21.38]', name: '考试前脑子空空' },
    			{ time: '[00:25.02]', name: '每天是彻夜地用功' },
    			{ time: '[00:27.05]', name: '希望在最后几周突击成功' },
    			{ time: '[00:30.10]', name: '放假回家的我 玩耍的我' },
    			{ time: '[00:33.41]', name: '叫一个快活' },
    			{ time: '[00:36.49]', name: '我左手柯南挂窗前' },
    			{ time: '[00:39.26]', name: '右手贝多芬箴言' },
    			{ time: '[00:42.20]', name: '早上背诵知识点' },
    			{ time: '[00:45.15]', name: '晚上习题卷' },
    			{ time: '[00:47.74]', name: '我忍辱负重为明天' },
    			{ time: '[00:50.97]', name: '抱佛脚为及格线' },
    			{ time: '[00:53.90]', name: '切记要日行一善' },
    			{ time: '[00:56.83]', name: '比方说三连' },
    			{ time: '[01:11.68]', name: '我左手柯南挂窗前' },
    			{ time: '[01:14.36]', name: '右手贝多芬箴言' },
    			{ time: '[01:17.27]', name: '早上背诵知识点' },
    			{ time: '[01:20.18]', name: '晚上习题卷' },
    			{ time: '[01:22.82]', name: '我忍辱负重为明天' },
    			{ time: '[01:26.09]', name: '抱佛脚为及格线' },
    			{ time: '[01:29.00]', name: '切记要日行一善' },
    			{ time: '[01:31.91]', name: '比方说三连' },
    		],
    	},

    ],
    Inv: 0, // 选项卡显示索引
    bof: null, // 播放的绿色logo,
    play: false, // 全局播放状态,
    listIndex: 1, // 歌单列表的的区别
    musicIndex: 0,
    startTime: '00:00',
    endTime: '00:00',
    move: 0,
    timeList: [],
    action: 0, // 歌词高亮索引
    m: 0, // 歌词盒子的滚动值
    liHeight: [],
    ge: null, // 这是歌词盒子的dom对象
    zhuangtai: true,
    aixin: false, // 收藏歌曲
    responseTimeMs2: null,
    responseTimeMs3: null,
    xunhuan: true, // 单曲循环false和列表循环true
  },
  mutations: {
    duration(e, dur) {
      e.endTime = dur;
      const timeList = [];// 把[00:00.0]时间转化为保留两位小数的秒数
      if (e.list.length > 0) {
        if (e.list[e.musicIndex].lyric.length > 0) {
          for (const i in e.list[e.musicIndex].lyric) {
            // 根据前面两位数*60得出秒数+后面的秒数
            timeList.push(parseFloat((e.list[e.musicIndex].lyric[i].time).substr(1, 3)) * 60 + parseFloat((e.list[e.musicIndex].lyric[i].time).substr(4, 9)));
          }
          e.timeList = timeList;
        }
      }
    },

    update(e, time) {
      // console.log(e,time)
      e.startTime = time.tosCur;
      e.move = time.cur / time.dur * 100;
      // console.log(e.move)
      	const t = (time.cur).toFixed(2);
      // console.log(t)
      if (e.list.length > 0) {
        if (e.list[e.musicIndex].lyric.length > 0) {
          setTimeout(() => {
            for (let i = 0; i < e.timeList.length; i++) {
              if (t > e.timeList[i] && t < e.timeList[i + 1]) {
                // 歌词的index，歌词亮光
                e.action = i;
                if (e.zhuangtai) {
                  if (i >= 4) {
                    e.m = e.liHeight[i] - e.liHeight[0] - e.liHeight[1] - e.liHeight[2];
                  }
                  if (e.ge != null) {
                    e.ge.style.transform = `translateY(${-e.m}px)`;
                  }
                }
              }
            }
          }, 101);
        }
      }
    },

  },
  actions: {

  },
  modules: {
  },
});
